package org.socialresume.client.mvp.presenter;


import org.enunes.gwt.mvp.client.EventBus;
import org.enunes.gwt.mvp.client.presenter.BasePresenter;
import org.socialresume.client.mvp.event.AdminModeEvent;
import org.socialresume.client.mvp.presenter.HeaderPresenter.Display;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.Window;
import com.google.inject.Inject;


public class HeaderPresenterImpl extends BasePresenter<Display> implements
		HeaderPresenter {
	
	@Inject
	public HeaderPresenterImpl(EventBus eventBus, Display display) {
		super(eventBus, display);
	}
	
	@Override
	public void bind() {
		registerHandler(display.getAdmin().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
			@Override
			public void onValueChange(ValueChangeEvent<Boolean> event) {
					eventBus.fireEvent(new AdminModeEvent(event.getValue()));
			}
		}));
		
		registerHandler(display.getContactButton().addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				actionContact();
			}
		}));
	}
	
	public void setAdminMode(boolean adminMode){
		if(adminMode){
			display.getStatusText().setText("Mode Administration");
		}else{
			display.getStatusText().setText("Mode Consultation");
		}
	}
	
	public void actionContact(){
		Window.alert("Contact me");
	}

}
